class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        long long left =0;
        long long right=0;
        long long n = nums.size();
        if(n==1)
        {
            if(nums[0]>=target)
                return 1;
            else 
                return 0;
        }
        int min_len = INT_MAX;
        long long s =nums[left];
        while(left<n && right<n)
        { 
            if(s<target)
            {
                if(++right<n)
                    s+=nums[right];
            }
            else 
            {
                int len = right-left+1;
                if(len<min_len)
                {
                    min_len = len;
                }
                if(left<n)
                    s-=nums[left++];
        }
        if(min_len == INT_MAX)
            return 0;
        return min_len;
    }
};

////////////////////////////////
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        long long n = nums.size();
        if(n==1)
        {
            if(nums[0]>=target)
                return 1;
            else 
                return 0;
        }
        int min_len = INT_MAX;
        int sum=0;
        for(int left=0,right=0;right<n;right++)
        {
            //进窗口
            sum+=nums[right];
            //判断大小
            while(sum>=target)
            {
                int len = right-left+1;
                if(len<min_len)
                    min_len = len;
                //出窗口
                sum-=nums[left++];
            }
        }
        if(min_len == INT_MAX)
            return 0;
        return min_len;
    }
};